package edu.ucsd.cse135.gas.logic.support;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

public class Specialization {

	private int id;
	private String name;
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	/** Method to get all specializations **/
	
	public static ArrayList<Specialization> getSpecializations() {
		
		try {
			
			Connection conn = Database.open();
		
			String sql = "SELECT id, name FROM specialization;";
		
			PreparedStatement preStmt = conn.prepareStatement(sql);
			ResultSet rs = preStmt.executeQuery();
			
			ArrayList<Specialization> sAl = new ArrayList<Specialization>();
			
			while(rs.next())
			{
				/** Iterate over the whole result set and put the different specializations into
				 *  a hash map and put this hash map afterwards into an array list for return**/
				
				Specialization s = new Specialization();
				
				s.setId(rs.getInt("id"));
				s.setName(rs.getString("name"));
				
				sAl.add(s);
			}
			
			rs.close();
			preStmt.close();
			Database.close();
			
			return sAl;
			
		}
		catch(Exception e) {
			
			Database.close();
			
			return null;
			
		}
	}
	
}
